<?php
class AjaxResponse{
	const typeApp = 0;
	const typeWin = 1;
	const typeContent = 2;
	
	public $hayError = null;
	public $hayContenido = null;
	public $arrIDs = null;
	public $htmlError = null;
	public $htmlContenido0 = null;
	public $htmlContenido1 = null;
	public $htmlContenido2 = null;
	public $htmlContenido3 = null;
	public $htmlContenido4 = null;
	
	public function AjaxResponse($contentType,$objError,$result){		
		include_once 'Vista/UI_Error.php';
		include_once 'Vista/UI_Contenido.php';		
		$this->hayError = $objError->hayError();	
		if(!$this->hayError){
			$this->hayContenido = (count($result)>0); 
			if($this->hayContenido){				
				switch ($contentType) {
					case self::typeApp:					
						$this->htmlContenido0 = UI_Contenido::ajax_appRowsToHtml($result);	
						$nomId = 'idAplicacion';			
					break;
					case self::typeWin:					
						$html = UI_Contenido::ajax_winRowsToHtml($result);
						$this->htmlContenido0=$html[0];				
						$this->htmlContenido1=$html[1];
						$this->htmlContenido2=$html[2];
						$this->htmlContenido3=$html[3];
						$this->htmlContenido4=$html[4];
						$nomId = 'idVentana';
					break;
					case self::typeContent:
						$this->htmlContenido0 = UI_Contenido::ajax_contentRowsToHtml($result);
						$nomId = 'idReporteLinea';
					break;
				}
				$this->arrIDs = array();
				foreach ($result as $row) {
					$this->arrIDs[] = $row[$nomId];
				}
			}			
		}
		else{
			$this->htmlError = UI_Error::imprimeError($objError,true);
		}		
	}
	
	public function send(){
		echo json_encode($this);
	}
	
}